<!DOCTYPE html>
<html><head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Green-forest &amp; Spring &amp; MyBatis Example</title>
	
	<link rel="stylesheet" type="text/css" href="css/reset.css">
	<link type="text/css" rel="stylesheet" href="css/shCoreDefault.css">
	<link rel="stylesheet" type="text/css" href="css/main.css">
	
	<script type="text/javascript" src="js/jquery-1.6.1-min.js"></script>
	<script type="text/javascript" src="js/jquery-ui-1.8.24.custom.min.js"></script>
	<script type="text/javascript" src="js/lang.js"></script>
	<script type="text/javascript" src="js/guide.js"></script>
	<script type="text/javascript" src="js/shCore.js"></script>
	<script type="text/javascript" src="js/shBrushJava.js"></script>
	<script type="text/javascript" src="js/shBrushXml.js"></script>
	<script type="text/javascript" src="js/effects.js"></script>
</head>
<body><span class="disablePreprocessingFlag"></span>
<div id="wrap">
	
	<div class="section">
		<a href="http://code.google.com/p/green-forest/">
			<img id="logo" src="i/gf-logo.png" alt="logo">
		</a>
		<h1>Green-forest &amp; Spring &amp; MyBatis Example</h1>
	</div>
	
	<div class="section toc"><dl><dt><a href="#p1">1. Overview</a></dt><dt><a href="#p2">2. Install</a></dt><dt><a href="#p3">3. Explanation of Example</a></dt></dl></div>
	
	<div class="importBlock" p-url="./chapters/spring-mybatis/01_intro.html">
<h2><a id="p1">1. Overview</a></h2>
<p><span class="start-space"></span>
This is the example of <span class="name">Spring Framework</span> application with <span class="name">Green-forest Framework</span> and <span class="name">MyBatis</span>.</p></div>
	<div class="importBlock" p-url="./chapters/spring-mybatis/02_install.html">
<h2><a id="p2">2. Install</a></h2>
<p><span class="start-space"></span>
You can download the example's <tt>war</tt> file from 
<a target="_blank" href="https://code.google.com/p/green-forest/downloads/list">download page</a>.
The zip archive with name like <tt>"green-forest-X.X-all.zip"</tt> contains all examples in folder "examples". 
</p><p><span class="start-space"></span>
Deploy <tt>gf-spring-mybatis.war</tt> file into your Web Server.
This application was tested on the <tt>Tomcat 7.0.28</tt> web server.
</p></div>
	<div class="importBlock" p-url="./chapters/spring-mybatis/03_details.html">
<h2><a id="p3">3. Explanation of Example</a></h2>

<p><span class="start-space"></span>
<span class="title">I. Action API</span>
<br><span class="start-space"></span>Package <b><tt>example.common.action</tt></b> contains Action API.
<br><span class="start-space"></span>Package <b><tt>example.app.handler</tt></b> contains handlers for this actions.

</p><p><span class="start-space"></span>Example of using this API from <tt>spring.web.AppController</tt>:
</p><div><div id="highlighter_909753" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">doGet(HttpServletRequest req, HttpServletResponse resp) {</code></div><div class="line number2 index1 alt1"> </div><div class="line number3 index2 alt2"><code class="java spaces">    </code><code class="java keyword">int</code> <code class="java plain">pageIndex = ...;</code></div><div class="line number4 index3 alt1"><code class="java spaces">    </code><code class="java keyword">int</code> <code class="java plain">limit = ...;</code></div><div class="line number5 index4 alt2"><code class="java spaces">    </code> </div><div class="line number6 index5 alt1"><code class="java spaces">    </code><code class="java plain">GetDocsPage action = </code><code class="java keyword">new</code> <code class="java plain">GetDocsPage(pageIndex, limit);</code></div><div class="line number7 index6 alt2"><code class="java spaces">    </code><code class="java plain">Page&lt;Doc&gt; page = app.invoke(action);</code></div><div class="line number8 index7 alt1"><code class="java spaces">    </code> </div><div class="line number9 index8 alt2"><code class="java spaces">    </code><code class="java plain">req.setAttribute(</code><code class="java string">"page"</code><code class="java plain">, page);</code></div><div class="line number10 index9 alt1"><code class="java spaces">    </code> </div><div class="line number11 index10 alt2"><code class="java plain">}</code></div><div class="line number12 index11 alt1"> </div><div class="line number13 index12 alt2"><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">doPost(HttpServletRequest req, HttpServletResponse resp) {</code></div><div class="line number14 index13 alt1"><code class="java spaces">    </code> </div><div class="line number15 index14 alt2"><code class="java spaces">    </code><code class="java keyword">int</code> <code class="java plain">id = ...;</code></div><div class="line number16 index15 alt1"><code class="java spaces">    </code><code class="java plain">String newName = ...;</code></div><div class="line number17 index16 alt2"><code class="java spaces">    </code> </div><div class="line number18 index17 alt1"><code class="java spaces">    </code><code class="java plain">RenameDoc action = </code><code class="java keyword">new</code> <code class="java plain">RenameDoc(id, newName);</code></div><div class="line number19 index18 alt2"><code class="java spaces">    </code><code class="java plain">app.invoke(action);</code></div><div class="line number20 index19 alt1"><code class="java spaces">    </code> </div><div class="line number21 index20 alt2"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>


<br>Example of app handler:
<div><div id="highlighter_75352" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div><div class="line number33 index32 alt2">33</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">package</code> <code class="java plain">example.app.handler;</code></div><div class="line number2 index1 alt1"> </div><div class="line number3 index2 alt2"><code class="java color1">@Mapping</code><code class="java plain">(GetDocsPage.</code><code class="java keyword">class</code><code class="java plain">)</code></div><div class="line number4 index3 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">GetDocsPageHandler </code><code class="java keyword">extends</code> <code class="java plain">Handler&lt;GetDocsPage&gt;{</code></div><div class="line number5 index4 alt2"><code class="java spaces">    </code> </div><div class="line number6 index5 alt1"><code class="java spaces">    </code><code class="java color1">@Inject</code></div><div class="line number7 index6 alt2"><code class="java spaces">    </code><code class="java plain">Storage storage;</code></div><div class="line number8 index7 alt1"> </div><div class="line number9 index8 alt2"><code class="java spaces">    </code><code class="java color1">@Override</code></div><div class="line number10 index9 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(GetDocsPage action) </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number11 index10 alt2"><code class="java spaces">        </code> </div><div class="line number12 index11 alt1"><code class="java spaces">        </code><code class="java plain">Input input = action.input();</code></div><div class="line number13 index12 alt2"><code class="java spaces">        </code><code class="java keyword">int</code> <code class="java plain">updatedPageIndex = input.pageIndex;</code></div><div class="line number14 index13 alt1"><code class="java spaces">        </code><code class="java keyword">int</code> <code class="java plain">updatedLimit = input.limit;</code></div><div class="line number15 index14 alt2"><code class="java spaces">        </code> </div><div class="line number16 index15 alt1"><code class="java spaces">        </code><code class="java keyword">if</code><code class="java plain">(updatedPageIndex &lt; </code><code class="java value">0</code><code class="java plain">){</code></div><div class="line number17 index16 alt2"><code class="java spaces">            </code><code class="java plain">updatedPageIndex = </code><code class="java value">0</code><code class="java plain">;</code></div><div class="line number18 index17 alt1"><code class="java spaces">        </code><code class="java plain">}</code></div><div class="line number19 index18 alt2"><code class="java spaces">        </code> </div><div class="line number20 index19 alt1"><code class="java spaces">        </code><code class="java keyword">if</code><code class="java plain">(updatedLimit &lt; </code><code class="java value">0</code><code class="java plain">){</code></div><div class="line number21 index20 alt2"><code class="java spaces">            </code><code class="java plain">updatedLimit = </code><code class="java value">0</code><code class="java plain">;</code></div><div class="line number22 index21 alt1"><code class="java spaces">        </code><code class="java plain">} </code><code class="java keyword">else</code> <code class="java keyword">if</code><code class="java plain">(updatedLimit &gt; </code><code class="java value">50</code><code class="java plain">){</code></div><div class="line number23 index22 alt2"><code class="java spaces">            </code><code class="java plain">updatedLimit = </code><code class="java value">50</code><code class="java plain">;</code></div><div class="line number24 index23 alt1"><code class="java spaces">        </code><code class="java plain">}</code></div><div class="line number25 index24 alt2"><code class="java spaces">        </code> </div><div class="line number26 index25 alt1"><code class="java spaces">        </code><code class="java plain">input.limit = updatedLimit;</code></div><div class="line number27 index26 alt2"><code class="java spaces">        </code><code class="java plain">input.pageIndex = updatedPageIndex;</code></div><div class="line number28 index27 alt1"><code class="java spaces">        </code> </div><div class="line number29 index28 alt2"><code class="java spaces">        </code><code class="java plain">storage.invoke(action);</code></div><div class="line number30 index29 alt1"><code class="java spaces">        </code> </div><div class="line number31 index30 alt2"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number32 index31 alt1"> </div><div class="line number33 index32 alt2"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>



<p class="more-top text-align-left"><span class="start-space"></span>
<span class="title">II. App Layer</span>
<br><span class="start-space"></span>
File <tt>gf-spring-mybatis.war/WEB-INF/<b>applicationContext.xml</b></tt> contains setup of App's 
<a target="_blank" href="./single-page.html#engine">Engine</a>:
</p><div><div id="highlighter_59587" class="syntaxhighlighter  xml"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="xml plain">&lt;</code><code class="xml keyword">bean</code> <code class="xml color1">id</code><code class="xml plain">=</code><code class="xml string">"appEngine"</code> <code class="xml color1">class</code><code class="xml plain">=</code><code class="xml string">"com.gf.core.Engine"</code><code class="xml plain">&gt;</code></div><div class="line number2 index1 alt1"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"name"</code> <code class="xml color1">value</code><code class="xml plain">=</code><code class="xml string">"App Engine"</code><code class="xml plain">/&gt;</code></div><div class="line number3 index2 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"scanAndPut"</code><code class="xml plain">&gt;</code></div><div class="line number4 index3 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number5 index4 alt2"><code class="xml spaces">            </code><code class="xml plain">&lt;</code><code class="xml keyword">value</code><code class="xml plain">&gt;example.app&lt;/</code><code class="xml keyword">value</code><code class="xml plain">&gt;</code></div><div class="line number6 index5 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;/</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number7 index6 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;/</code><code class="xml keyword">property</code><code class="xml plain">&gt;</code></div><div class="line number8 index7 alt1"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"contextObjects"</code><code class="xml plain">&gt;</code></div><div class="line number9 index8 alt2"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number10 index9 alt1"><code class="xml spaces">            </code><code class="xml plain">&lt;</code><code class="xml keyword">ref</code> <code class="xml color1">bean</code><code class="xml plain">=</code><code class="xml string">"storage"</code><code class="xml plain">/&gt;</code></div><div class="line number11 index10 alt2"><code class="xml spaces">        </code><code class="xml plain">&lt;/</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number12 index11 alt1"><code class="xml spaces">    </code><code class="xml plain">&lt;/</code><code class="xml keyword">property</code><code class="xml plain">&gt;</code></div><div class="line number13 index12 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"configValues"</code><code class="xml plain">&gt;</code></div><div class="line number14 index13 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">props</code><code class="xml plain">&gt;</code></div><div class="line number15 index14 alt2"><code class="xml spaces">            </code><code class="xml plain">&lt;</code><code class="xml keyword">prop</code> <code class="xml color1">key</code><code class="xml plain">=</code><code class="xml string">"com.gf.key.TraceHandlers"</code><code class="xml plain">&gt;true&lt;/</code><code class="xml keyword">prop</code><code class="xml plain">&gt;</code></div><div class="line number16 index15 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;/</code><code class="xml keyword">props</code><code class="xml plain">&gt;</code></div><div class="line number17 index16 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;/</code><code class="xml keyword">property</code><code class="xml plain">&gt;</code></div><div class="line number18 index17 alt1"><code class="xml plain">&lt;/</code><code class="xml keyword">bean</code><code class="xml plain">&gt;</code></div><div class="line number19 index18 alt2"> </div><div class="line number20 index19 alt1"><code class="xml plain">&lt;</code><code class="xml keyword">bean</code> <code class="xml color1">id</code><code class="xml plain">=</code><code class="xml string">"app"</code> <code class="xml color1">class</code><code class="xml plain">=</code><code class="xml string">"example.app.AppImpl"</code><code class="xml plain">&gt;</code></div><div class="line number21 index20 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">constructor-arg</code> <code class="xml color1">ref</code><code class="xml plain">=</code><code class="xml string">"appEngine"</code><code class="xml plain">/&gt;</code></div><div class="line number22 index21 alt1"><code class="xml plain">&lt;/</code><code class="xml keyword">bean</code><code class="xml plain">&gt;</code></div></div></td></tr></tbody></table></div></div>



<p class="more-top text-align-left"><span class="start-space"></span>
<span class="title">III. Storage Layer</span>
<br><span class="start-space"></span>
File <tt>gf-spring-mybatis.war/WEB-INF/<b>applicationContext.xml</b></tt> contains setup of Storage's 
<a target="_blank" href="./single-page.html#engine">Engine</a>:
</p><div><div id="highlighter_911095" class="syntaxhighlighter  xml"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="xml plain">&lt;</code><code class="xml keyword">bean</code> <code class="xml color1">id</code><code class="xml plain">=</code><code class="xml string">"storageEngine"</code> <code class="xml color1">class</code><code class="xml plain">=</code><code class="xml string">"com.gf.core.Engine"</code><code class="xml plain">&gt;</code></div><div class="line number2 index1 alt1"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"name"</code> <code class="xml color1">value</code><code class="xml plain">=</code><code class="xml string">"Storage Engine"</code><code class="xml plain">/&gt;</code></div><div class="line number3 index2 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"scanAndPut"</code><code class="xml plain">&gt;</code></div><div class="line number4 index3 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number5 index4 alt2"><code class="xml spaces">            </code><code class="xml plain">&lt;</code><code class="xml keyword">value</code><code class="xml plain">&gt;mybatis.storage&lt;/</code><code class="xml keyword">value</code><code class="xml plain">&gt;</code></div><div class="line number6 index5 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;/</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number7 index6 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;/</code><code class="xml keyword">property</code><code class="xml plain">&gt;</code></div><div class="line number8 index7 alt1"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"contextObjects"</code><code class="xml plain">&gt;</code></div><div class="line number9 index8 alt2"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number10 index9 alt1"><code class="xml spaces">            </code><code class="xml plain">&lt;</code><code class="xml keyword">ref</code> <code class="xml color1">bean</code><code class="xml plain">=</code><code class="xml string">"sqlSessionFactory"</code><code class="xml plain">/&gt;</code></div><div class="line number11 index10 alt2"><code class="xml spaces">        </code><code class="xml plain">&lt;/</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number12 index11 alt1"><code class="xml spaces">    </code><code class="xml plain">&lt;/</code><code class="xml keyword">property</code><code class="xml plain">&gt;</code></div><div class="line number13 index12 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"filterTypes"</code><code class="xml plain">&gt;</code></div><div class="line number14 index13 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number15 index14 alt2"><code class="xml spaces">            </code><code class="xml plain">&lt;</code><code class="xml keyword">value</code><code class="xml plain">&gt;com.gf.components.mybatis.SqlSessionInInvoke&lt;/</code><code class="xml keyword">value</code><code class="xml plain">&gt;</code></div><div class="line number16 index15 alt1"><code class="xml spaces">        </code><code class="xml plain">&lt;/</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number17 index16 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;/</code><code class="xml keyword">property</code><code class="xml plain">&gt;</code></div><div class="line number18 index17 alt1"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"initializers"</code><code class="xml plain">&gt;</code></div><div class="line number19 index18 alt2"><code class="xml spaces">        </code><code class="xml plain">&lt;</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number20 index19 alt1"><code class="xml spaces">            </code><code class="xml plain">&lt;</code><code class="xml keyword">bean</code> <code class="xml color1">class</code><code class="xml plain">=</code><code class="xml string">"com.gf.components.mybatis.InjectMappers"</code><code class="xml plain">/&gt;</code></div><div class="line number21 index20 alt2"><code class="xml spaces">        </code><code class="xml plain">&lt;/</code><code class="xml keyword">list</code><code class="xml plain">&gt;</code></div><div class="line number22 index21 alt1"><code class="xml spaces">    </code><code class="xml plain">&lt;/</code><code class="xml keyword">property</code><code class="xml plain">&gt;</code></div><div class="line number23 index22 alt2"><code class="xml plain">&lt;/</code><code class="xml keyword">bean</code><code class="xml plain">&gt;</code></div><div class="line number24 index23 alt1"> </div><div class="line number25 index24 alt2"><code class="xml plain">&lt;</code><code class="xml keyword">bean</code> <code class="xml color1">id</code><code class="xml plain">=</code><code class="xml string">"storage"</code> <code class="xml color1">class</code><code class="xml plain">=</code><code class="xml string">"example.storage.StorageImpl"</code><code class="xml plain">&gt;</code></div><div class="line number26 index25 alt1"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">constructor-arg</code> <code class="xml color1">ref</code><code class="xml plain">=</code><code class="xml string">"storageEngine"</code><code class="xml plain">/&gt;</code></div><div class="line number27 index26 alt2"><code class="xml plain">&lt;/</code><code class="xml keyword">bean</code><code class="xml plain">&gt;</code></div></div></td></tr></tbody></table></div></div>


<br>Example of storage handler:
<div><div id="highlighter_639004" class="syntaxhighlighter  java"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="java keyword">package</code> <code class="java plain">mybatis.storage.handler;</code></div><div class="line number2 index1 alt1"> </div><div class="line number3 index2 alt2"><code class="java color1">@Mapping</code><code class="java plain">(GetDocsPage.</code><code class="java keyword">class</code><code class="java plain">)</code></div><div class="line number4 index3 alt1"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">GetDocsPageHandler </code><code class="java keyword">extends</code> <code class="java plain">Handler&lt;GetDocsPage&gt;{</code></div><div class="line number5 index4 alt2"><code class="java spaces">    </code> </div><div class="line number6 index5 alt1"><code class="java spaces">    </code><code class="java color1">@Inject</code></div><div class="line number7 index6 alt2"><code class="java spaces">    </code><code class="java plain">DocMapper docMapper;</code></div><div class="line number8 index7 alt1"> </div><div class="line number9 index8 alt2"><code class="java spaces">    </code><code class="java color1">@Override</code></div><div class="line number10 index9 alt1"><code class="java spaces">    </code><code class="java keyword">public</code> <code class="java keyword">void</code> <code class="java plain">invoke(GetDocsPage action) </code><code class="java keyword">throws</code> <code class="java plain">Exception {</code></div><div class="line number11 index10 alt2"><code class="java spaces">        </code> </div><div class="line number12 index11 alt1"><code class="java spaces">        </code><code class="java plain">Input input = action.input();</code></div><div class="line number13 index12 alt2"><code class="java spaces">        </code> </div><div class="line number14 index13 alt1"><code class="java spaces">        </code><code class="java keyword">int</code> <code class="java plain">limit = input.limit;</code></div><div class="line number15 index14 alt2"><code class="java spaces">        </code><code class="java keyword">int</code> <code class="java plain">pageIndex = input.pageIndex;</code></div><div class="line number16 index15 alt1"><code class="java spaces">        </code><code class="java keyword">int</code> <code class="java plain">offset = pageIndex*limit;</code></div><div class="line number17 index16 alt2"><code class="java spaces">        </code> </div><div class="line number18 index17 alt1"><code class="java spaces">        </code><code class="java plain">List&lt;Doc&gt; list = docMapper.getDocsPage(limit, offset);</code></div><div class="line number19 index18 alt2"><code class="java spaces">        </code> </div><div class="line number20 index19 alt1"><code class="java spaces">        </code><code class="java plain">Integer count = subInvoke(</code><code class="java keyword">new</code> <code class="java plain">GetDocsCount());</code></div><div class="line number21 index20 alt2"> </div><div class="line number22 index21 alt1"><code class="java spaces">        </code><code class="java plain">action.setOutput(</code><code class="java keyword">new</code> <code class="java plain">Page&lt;Doc&gt;(list, pageIndex, limit, count));</code></div><div class="line number23 index22 alt2"><code class="java spaces">        </code> </div><div class="line number24 index23 alt1"><code class="java spaces">    </code><code class="java plain">}</code></div><div class="line number25 index24 alt2"> </div><div class="line number26 index25 alt1"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div>


<p class="more-top text-align-left"><span class="start-space"></span>
<span class="title">IV. MyBatis</span>
<br><span class="start-space"></span>
File <tt>gf-spring-mybatis.war/WEB-INF/<b>applicationContext.xml</b></tt> contains setup of MyBatis:
</p><div><div id="highlighter_333993" class="syntaxhighlighter  xml"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="xml plain">&lt;</code><code class="xml keyword">bean</code> <code class="xml color1">id</code><code class="xml plain">=</code><code class="xml string">"sqlSessionFactory"</code> <code class="xml color1">class</code><code class="xml plain">=</code><code class="xml string">"org.mybatis.spring.SqlSessionFactoryBean"</code><code class="xml plain">&gt;</code></div><div class="line number2 index1 alt1"><code class="xml spaces">  </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"dataSource"</code> <code class="xml color1">ref</code><code class="xml plain">=</code><code class="xml string">"dataSource"</code> <code class="xml plain">/&gt;</code></div><div class="line number3 index2 alt2"><code class="xml spaces">  </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"mapperLocations"</code> <code class="xml color1">value</code><code class="xml plain">=</code><code class="xml string">"classpath*:mybatis/mapper/**/*.xml"</code> <code class="xml plain">/&gt;</code></div><div class="line number4 index3 alt1"><code class="xml spaces">  </code><code class="xml plain">&lt;</code><code class="xml keyword">property</code> <code class="xml color1">name</code><code class="xml plain">=</code><code class="xml string">"transactionFactory"</code><code class="xml plain">&gt;</code></div><div class="line number5 index4 alt2"><code class="xml spaces">    </code><code class="xml plain">&lt;</code><code class="xml keyword">bean</code> <code class="xml color1">class</code><code class="xml plain">=</code><code class="xml string">"org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory"</code> <code class="xml plain">/&gt;</code></div><div class="line number6 index5 alt1"><code class="xml spaces">  </code><code class="xml plain">&lt;/</code><code class="xml keyword">property</code><code class="xml plain">&gt;  </code></div><div class="line number7 index6 alt2"><code class="xml plain">&lt;/</code><code class="xml keyword">bean</code><code class="xml plain">&gt;</code></div></div></td></tr></tbody></table></div></div>



</div>

</div>

<div class="importBlock" p-url="./chapters/footer.html">
<div id="copyright">
<a href="http://code.google.com/p/green-forest/"><span class="name">Green-forest Framework</span></a> was originally created in 2011 and is still maintained by Evgeny Dolganov. 
Copyright 2011-2013 <a target="_blank" href="http://ru.linkedin.com/pub/evgeny-dolganov/17/a71/464">Evgeny Dolganov</a>.
</div>

<div id="toTop">Back to Top</div></div>


</body></html>